#ifndef __POPUPBLOWFISKKEYMSG_HPP__
#define __POPUPBLOWFISKKEYMSG_HPP__

#include "PopupMessage.hpp"
#include "PopupAbstractMessage.hpp"
#include "PopupSSL.hpp"

namespace Popup
{
  struct BlowfishKeyMsg : public AbstractMessage
  {
    enum { BLOWFISH_KEY = 0x4321 };

    //! Constructor used in order to send our blowfish key to
    //! a foreign host using RSA encryption public key contained
    //! in the given SSL context.
    BlowfishKeyMsg(const SslContext *p_sslContext) :
      AbstractMessage(POPUP_MSG_TYPE_BLOWFISH_KEY, POPUP_ENCRYPTION_RSA),
      sslContext(p_sslContext) {}

    //! Constructor used in order to received a blowfish key from
    //! a foreign host. Key will be decrypted using private RSA
    //! key contained in the given SSL context.
    BlowfishKeyMsg(const Message *p_message);

    ~BlowfishKeyMsg() {}

    //!@Override
    bool onSend();

    //!@Override
    bool onReceive();

    inline const BlowfishKey & getKey() { return receivedKey; }

  private:
    //! Blowfish key received from a foreign host
    BlowfishKey receivedKey;
    const SslContext *sslContext;
  };
}

#endif // __POPUPBLOWFISKKEYMSG_HPP__
